package com.ml.util;

import java.math.BigDecimal;

public class MathUtils {

	public static long BigDecimalToLong(BigDecimal old, int offset) {
		BigDecimal offDecimal = new BigDecimal(Math.pow(10, offset));
		if (offset > 0) {
			return old.multiply(offDecimal).longValue();
		} else if (offset < 0) {
			return old.divide(offDecimal).longValue();
		}
		return old.longValue();
	}

	public static BigDecimal LongToBigDecimal(long old, int offset) {
		BigDecimal oldDecimal = new BigDecimal(old);
		BigDecimal offDecimal = new BigDecimal(Math.pow(10, offset));
		if (offset > 0) {
			return oldDecimal.divide(offDecimal);
		} else if (offset < 0) {
			return oldDecimal.multiply(offDecimal);
		}
		return oldDecimal;
	}
}
